package com.gitee.srurl.core.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.gitee.srurl.core.util.valid.AddGroup;
import com.gitee.srurl.core.util.valid.UpdateGroup;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author zxw
 * @date 2023/4/27 21:57
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("suc_blacklist")
public class SucBlacklistDomain implements Serializable {

    @Serial
    private static final long serialVersionUID = 7053534459691899661L;

    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * host
     */
    @NotBlank(message = "host不能为空！", groups = {AddGroup.class, UpdateGroup.class})
    @Pattern(regexp = "^(http|https)://.+", message = "域名无效！", groups = {AddGroup.class, UpdateGroup.class})
    private String host;

    /**
     * 状态(1:启用,0:禁用)
     */
    @NotBlank(message = "状态不能为空！", groups = {AddGroup.class, UpdateGroup.class})
    @Pattern(regexp = "^0|1$", message = "状态参数错误", groups = {AddGroup.class, UpdateGroup.class})
    private String status;

    /**
     * 创建时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 创建ID
     */
    @TableField(fill = FieldFill.INSERT)
    private Long createId;

    /**
     * 更新时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 更新ID
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateId;
}
